***File used to create statistics tables for Murphy et al. "Chatting at Church: Information Diffusion through Religious Networks"

clear all
macro drop _all

*CUSTOM DO FILES
ssc install matmap

global user "[INSERT PATH HERE]"
cd "${user}"

use descriptive_data, clear
sort indvid

***Table 1***

gen religiontable=.
replace religiontable=1 if religion==1|religion==12|religion==9|religion==7
replace religiontable=2 if religion==5
replace religiontable=3 if religion==2
replace religiontable=4 if religion==20
replace religiontable=5 if religion==11
replace religiontable=6 if religion==10
replace religiontable=7 if religion==17
replace religiontable=8 if religion==3
replace religiontable=9 if religion==6
replace religiontable=10 if religion==16
replace religiontable=11 if religion==4
replace religiontable=12 if religion==18

label define religiontable 1 "Pentecostal/Charismatic" 2 "Anglican" 3 "Roman Catholic" 4 "Salvation Army" 5 "Quaker (Friends)" 6 "Seventh Day Adventist" 7 "Muslim" 8 "Baptist" 9 "Presbyterian" 10 "African Traditional" 11 "Orthodox Christian" 12 "No Religion" 
label values religiontable religiontable

tab religiontable, matcell(list)
mat rownames list="Pentecostal/Charismatic" "Anglican" "Roman Catholic" "Salvation Army" "Quaker (Friends)" "Seventh Day Adventist" "Muslim" "Baptist" "African Traditional" "Orthodox Christian" "No Religion" 
frmttable using "religionlist" , statmat(list)  sdec(0) varlabels ctitles(Religion, Individuals n=884) tex frag replace


***Table 2***

use "descriptive_data", clear

replace electricitygrid=0 if electricitygrid==2
replace solarpanels=0 if solarpanels==2
gen farmwagework=(offfarmlabor==1&labor1type==1)
gen purchasedseed=(nocropseedpmt==0)
gen cropharvestvalueperhecthous=cropharvestvalueperhec/1000


label var age "Age$^a$"
label var yrseduc "Years of education$^b$"
label var math1 "Mathematics ability$^c$"
label var hhsize "Household size$^d$"
label var orgtwofullseas "Used organic inputs (past two seasons)"
label var inorgtwofullseas "Used inorganic inputs (past two seasons)"
label var comptwofullseas "Used compost "
label var manutwofullseas "Used fresh manure "
label var ureatwofullseas "Used urea "
label var daptwofullseas "Used DAP "
label var cantwofullseas "Used CAN "
label var npktwofullseas "Used NPK "
label var fem "Female"
label var widow "Widow"
label var farmer "Farmer"
label var agngo "Contact with ag. NGO"
label variable totalcultareaacres "Total farm area (acres)"
label variable bukusu "Bukusu"
label variable luhyaother "Other Luhya subtribe"
label variable tribeother "Other tribe"
label var iteso "Iteso"
label var river "Water from river"
label var electricitygrid "Connected to electirical grid"
label var metalroof "Metal roof"
label var mudfloor "Mud floor"
label var multspouse "Polygamous household"
label var solarpanels "Solar panels"
label var farmwagework "Ag. wage labor (last 30 days)"
label var plotinheritedormarriage "Inherited land (from parents or spouse)"
label var maizeused "Grew maize"
label var beansused "Grew beans"
label var cassavaused "Grew cassava"
label var milletused "Grew millet"
label var sugarused "Grew sugarcane"
label var tobaccoused "Grew tobacco"
label var cropharvestvalueperhec "Crop harvest value (KSh/ha)"
label var monocrop "Monocrop"
label var purchasedseed "Purchased seed"
label var hirelabor "Hired labor"
label var cropharvestvalueperhecthous "Maize harvest value (1000 KSh/ha)"
label var totalcropharvestperhect "Total maize harvest (Kg/ha)"
label var assetindx "Asset index$^e$"
label var ownplot "Own plot"
label var hhid "Unique household id"
label var indvid "Unique individual id"
label var villagenum "Village id"
label var religion "Religion"
label var tlu "Tropical livestock units"
label var hhead "Household head"
label var nocropseedpmt "Did not pay for crop seeds"
label var floor "Floor material"

*between, within village variation
xtsum cropharvestvalueperhecthous, i(villagenum)

*sum stats

global sumstatvarsindv1 age yrseduc math1 farmer plotinheritedormarriage farmwagework female widow bukusu luhyaother iteso  
global sumstatvarshh hhsize assetindx totalcultareaacres comptwofullseas manutwofullseas ureatwofullseas daptwofullseas npktwofullseas cantwofullseas maizeused beansused cassavaused milletused sugarused tobaccoused NGO river electricitygrid solarpanels metalroof mudfloor multspouse cropharvestvalueperhecthous ownplot monocrop purchasedseed hirelabor

estpost summarize $sumstatvarsindv1
matrix mymat = e(mean)\ e(sd)\ e(min)\ e(max)
estpost summarize $sumstatvarshh if hhead==1
matrix mymat2=e(mean)\ e(sd)\ e(min)\ e(max)
matrix newmat = mymat , mymat2
matrix newmat2=newmat'
matmap newmat2 newmat2, map(round(@, 0.01))

esttab matrix(newmat2) using summarystats.tex, replace collabels("Mean" "Std. Dev." "Min" "Max") varlabels(, elist(iteso \hline multspouse \hline)) refcat(age "\rg{\textbf{Individual level (n=884)}}" math1 "\rg{Yes=1}" hhsize "\rg{\textbf{Household level (n=548)}}" comptwofullseas "\rg{Yes=1}" cropharvestvalueperhecthous "\rg{\textbf{LR Main Maize Plot (n=518)}}" ownplot "\rg{Yes=1}", nolabel) nomtitles sfmt(3) nonumbers label


***Appendix figure A3***

hist cropharvestvalueperhecthous, freq
graph export "harvesthist.png", as(png) replace


***Appendix table A2***


preserve
label var churchattendance "RI Size"
label var churchfreq "RI attendance (1=daily, 9=never)$ \dagger $"
order churchattendance churchfreq religion catholic anglican pentecostal christianother religionother
sum churchattendance, detail
drop if churchattendance<r(p5)
sum churchattendance, detail
drop if churchattendanc>r(p95)
drop if churchfreq==10

gen religioncondensed=(catholic==1)
replace religioncondensed=2 if pentecostal==1
replace religioncondensed=3 if anglican==1
replace religioncondensed=4 if christianother==1
replace religioncondensed=5 if religionother==1

label define religioncondensed 1 "Catholic" 2 "Pentecostal/Charistmatic" 3 "Anglican" 4 "Other Christian" 5 "Other Religion"
label values religioncondensed religioncondensed

global religionvars catholic anglican pentecostal christianother religionother
global sumvars churchattendance churchfreq bukusu luhyaother iteso tribeother

by religioncondensed, sort: eststo: estpost summarize $sumvars

esttab using churchattendance.tex, cells("mean(lab(Mean) fmt(2)) sd(lab(Std. Dev.) fmt(2))") replace label nodepvar nomtitles nonumbers ///
mgroups("Catholic" "Pentecostal/Charistmatic" "Anglican" "Other Christian" "Other Religion", pattern(1 1 1 1 1) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span}))
restore


***Appendix Tables A4-1, A4-2, A4-3***

egen N=count(indvid), by(villagenum)
global collapsevars N age yrseduc math1 farmer plotinheritedormarriage farmwagework female widow anglican catholic pentecostal christianother religionother bukusu luhyaother iteso tribeother hhsize assetindx totalcultareaacres comptwofullseas manutwofullseas ureatwofullseas daptwofullseas npktwofullseas cantwofullseas maizeused beansused cassavaused milletused sugarused tobaccoused NGO river electricitygrid solarpanels metalroof mudfloor multspouse cropharvestvalueperhecthous monocrop purchasedseed hirelabor
global collapsevarssd
foreach var of varlist $collapsevars{
gen `var'sd=`var'
global collapsevarssd $collapsevarssd `var'sd
order `var'sd, after(`var')
}

collapse (mean) ($collapsevars) (sd) ($collapsevarssd), by(villagenum county)
foreach var of varlist $collapsevars{
order `var'sd, after(`var')
}

label var N "N"
label var catholic "Catholic"
label var pentecostal "Pentecostal"
label var anglican "Anglican"
label var pentecostal "Pentecostal/Charismatic"
label var christianother "Other Christian"
label var religionother "Other Religion"
label var age "Age$^a$"
label var yrseduc "Years of education$^b$"
label var math1 "Mathematics ability$^c$"
label var hhsize "Household size$^d$"
label var comptwofullseas "Used compost "
label var manutwofullseas "Used fresh manure "
label var ureatwofullseas "Used urea "
label var daptwofullseas "Used DAP "
label var cantwofullseas "Used CAN "
label var npktwofullseas "Used NPK "
label var female "Female"
label var widow "Widow"
label var farmer "Farmer"
label var NGO "Contact with NGO"
label var totalcultareaacres "Total farm area (acres)"
label var bukusu "Bukusu"
label var luhyaother "Other Luhya subtribe"
label var iteso "Iteso"
label var tribeother "Other tribe"
label var river "Water from river"
label var electricitygrid "Electrical grid connection"
label var metalroof "Metal roof"
label var mudfloor "Mud floor"
label var multspouse "Polygamous household"
label var solarpanels "Solar panels"
label var farmwagework "Ag. wage labor (last 30 days)"
label var plotinheritedormarriage "Inherited land"
label var maizeused "Grew maize"
label var beansused "Grew beans"
label var cassavaused "Grew cassava"
label var milletused "Grew millet"
label var sugarused "Grew sugarcane"
label var tobaccoused "Grew tobacco"
label var cropharvestvalueperhecthous "Crop harvest value (KSh/ha)"
label var monocrop "Monocrop"
label var purchasedseed "Purchased seed"
label var hirelabor "Hired labor"
label var cropharvestvalueperhecthous "Yield value (1000 KSh/ha)"
label var assetindx "Asset index$^e$"
label var county "County ID"



preserve
keep if county==1
mkmat $collapsevars, mat(villstats) rownames(villagenum)
mat villstats1=villstats'
matmap villstats1 villstats1, map(round(@, 0.01))
frmttable using villstats1.tex, tex statmat(villstats1) replace frag sdec(2) ///
ctitle("Village" "13" "14" "15" "17" "18") varlabels
restore
preserve
keep if county==2
mkmat $collapsevars, mat(villstats) rownames(villagenum)
mat villstats1=villstats'
matmap villstats1 villstats1, map(round(@, 0.01))
frmttable using villstats2.tex, tex statmat(villstats1) replace frag sdec(2) ///
ctitle("Village" "6" "7" "8" "9" "10" "11" "12") varlabels
restore
preserve
keep if county==3
mkmat $collapsevars, mat(villstats) rownames(villagenum)
mat villstats1=villstats'
matmap villstats1 villstats1, map(round(@, 0.01))
frmttable using villstats3.tex, tex statmat(villstats1) replace frag sdec(2) ///
ctitle("Village" "1" "2" "3" "4" "5" "16") varlabels
restore



